# 使用地理编码服务API
import requests
import json

# 请求用户输入地址
print("请输入地址：")
address_input = input()
# 将输入的地址赋值给变量
address = address_input
# 打印确认信息
print(f"您输入的地址是：{address}")
# 高德Key
amap_api_key = "803861c34e31752fb8c5863ba3aa62b4"
# 将地址转换为经纬度
url = f"http://restapi.amap.com/v3/geocode/geo?key={amap_api_key}&address={address}"
response = requests.get(url)
data = json.loads(response.text)

if data['status'] == '1':
    location = data['geocodes'][0]['location']
    print(f'纬度: {location.split(",")[1]}, 经度: {location.split(",")[0]}')  # 注意高德返回的经纬度顺序
else:
    print("地理编码失败")